package com.zh.blog.strategy.context;

import com.zh.blog.dto.ArticleSearchDto;
import com.zh.blog.strategy.SearchStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import static com.zh.blog.enums.SearchModeEnum.getStrategy;

/**
 * 搜索策略上下文
 * @author ZhengHao
 * Created At 2022/8/22.
 **/
@Service
public class SearchStrategyContext {
    @Value("${search.mode}")
    private String searchMode;

    @Autowired
    private Map<String, SearchStrategy> searchStrategyMap;

    public List<ArticleSearchDto> executeSearchStrategy(String keywords) {
        return searchStrategyMap.get(getStrategy(searchMode)).searchArticle(keywords);
    }
}